package office.action.hr;

import java.util.List;
import javax.annotation.Resource;
import current.security.user.manager.service.UserManagerService;
import office.action.hr.form.OfficesuppliesEntryForm;
import office.action.hr.form.OfficesuppliesForm;
import office.service.hr.IOfficesuppliesEntryService;
import office.service.hr.IOfficesuppliesService;
import platform.common.action.BaseAction;

@SuppressWarnings("serial")
public class OfficesuppliesEntryAction extends BaseAction{

	private IOfficesuppliesEntryService officesuppliesEntryService;
	private IOfficesuppliesService officesuppliesService;
	@SuppressWarnings("unchecked")
	private List wrapperList;
	private String id;
	private OfficesuppliesEntryForm objctForm;
	private String oficesuppliesId;			//办公用品id
	@Resource
	private UserManagerService userManagerService;
	private OfficesuppliesForm officesuppliesForm;
	@SuppressWarnings("unchecked")
	private List userList;
	/**
	 * 获取申请办公用品信息
	 * @return
	 * @throws Exception
	 */
	public String officesuppliesEntryList()throws Exception{
		String userId = getUserId();
		wrapperList = officesuppliesEntryService.getOfficesuppliesEntryList(userId);
		return "showList";
	}
	
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoAdd()throws Exception{
		this.gotoUserList();
		return "gotoEdit";
	}
	public void gotoUserList()throws Exception{
		this.setUserList(userManagerService.getUserByRoleAndCompany("xzrsjl",getUserCompanyId()));
	}
	
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEdit()throws Exception{
		this.gotoUserList();
		objctForm = officesuppliesEntryService.getById(id);
		return "gotoEdit";
	}
	/**
	 * 添加或编辑数据
	 * @return
	 * @throws Exception
	 */
	public String editData() throws Exception{
		try {
			String userId = getUserId();
			objctForm.setEntryUser(userId);
			officesuppliesEntryService.editOfficesuppliesEntry(objctForm);
			if(null==objctForm.getId() || ("").equals(objctForm.getId())){
				this.getAjaxMessagesJson().setMessage(true, "", "办公用品申请成功");
			}else{
				this.getAjaxMessagesJson().setMessage(true, "", "办公用品申请编辑成功");
			}
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 初始化可用操作
	 * @return
	 * @throws Exception
	 */
	public String gotoEditXml()throws Exception{
		objctForm = officesuppliesEntryService.getById(id);
		return "editXml";
	}
	/**
	 * 初始化删除
	 * @return
	 * @throws Exception
	 */
	public String gotoDel()throws Exception{
		return "gotoDel";
	}
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	public String delData()throws Exception{
		try {
			officesuppliesEntryService.deleteById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "删除成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 初始化切换状态
	 * @return
	 * @throws Exception
	 */
	public String gotoChangeState()throws Exception{
		return "gotoChangeState";
	}
	/**
	 * 切换状态
	 * @return
	 * @throws Exception
	 */
	public String changeState()throws Exception{
		try {
			officesuppliesEntryService.changeState(objctForm);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	
	@SuppressWarnings("unchecked")
	public List getWrapperList() {
		return wrapperList;
	}

	@SuppressWarnings("unchecked")
	public void setWrapperList(List wrapperList) {
		this.wrapperList = wrapperList;
	}

	public IOfficesuppliesEntryService getOfficesuppliesEntryService() {
		return officesuppliesEntryService;
	}

	public void setOfficesuppliesEntryService(
			IOfficesuppliesEntryService officesuppliesEntryService) {
		this.officesuppliesEntryService = officesuppliesEntryService;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public OfficesuppliesEntryForm getObjctForm() {
		return objctForm;
	}

	public void setObjctForm(OfficesuppliesEntryForm objctForm) {
		this.objctForm = objctForm;
	}

	public String getOficesuppliesId() {
		return oficesuppliesId;
	}

	public void setOficesuppliesId(String oficesuppliesId) {
		this.oficesuppliesId = oficesuppliesId;
	}

	public OfficesuppliesForm getOfficesuppliesForm() {
		return officesuppliesForm;
	}

	public void setOfficesuppliesForm(OfficesuppliesForm officesuppliesForm) {
		this.officesuppliesForm = officesuppliesForm;
	}

	public IOfficesuppliesService getOfficesuppliesService() {
		return officesuppliesService;
	}

	public void setOfficesuppliesService(
			IOfficesuppliesService officesuppliesService) {
		this.officesuppliesService = officesuppliesService;
	}

	@SuppressWarnings("unchecked")
	public List getUserList() {
		return userList;
	}

	@SuppressWarnings("unchecked")
	public void setUserList(List userList) {
		this.userList = userList;
	}

	public UserManagerService getUserManagerService() {
		return userManagerService;
	}

	public void setUserManagerService(UserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}
	
}
